using UnityEngine;

[ExecuteInEditMode]
public class CheckpointForMT : MonoBehaviour
{
	public enum stateCP
	{
		hide = 0,
		show = 1,
		showAndActiv = 2
	}

	public stateCP curState;

	public GameObject noActiveObj;

	public GameObject activeObj;

	public GameObject arrow;

	public GameObject bigArrow;

	public Collider colliderMT;

	private MissionTargetCheckpoint curMTCheckpoint;

	private void Start()
	{
		curMTCheckpoint = GetComponentInParent<MissionTargetCheckpoint>();
		if (colliderMT == null)
		{
			colliderMT = GetComponent<Collider>();
		}
		NJGMapItem component = activeObj.GetComponent<NJGMapItem>();
		NJGMapItem component2 = noActiveObj.GetComponent<NJGMapItem>();
		if (component != null)
		{
			component.type = 8;
		}
		if (component2 != null)
		{
			component2.type = 9;
		}
		if (controllerMenu.thisScript != null)
		{
			SetStateCheckpoint(stateCP.hide, true);
		}
		else
		{
			SetStateCheckpoint(curState, true);
		}
	}

	private void OnTriggerEnter(Collider other)
	{
		if (curState != stateCP.showAndActiv)
		{
			return;
		}
		SynchronizedGameObject componentInParent = other.transform.GetComponentInParent<SynchronizedGameObject>();
		if (componentInParent == null)
		{
			return;
		}
		bool flag = false;
		if (!(curMTCheckpoint != null))
		{
			return;
		}
		switch (curMTCheckpoint.triggerTarget)
		{
		case EntityForMT.player:
		{
			PlayerBehavior playerBehavior = componentInParent as PlayerBehavior;
			if (playerBehavior != null)
			{
				flag = true;
			}
			break;
		}
		case EntityForMT.car:
		{
			CarBehavior carBehavior2 = componentInParent as CarBehavior;
			if (carBehavior2 != null && !carBehavior2.carWithWeapon && !carBehavior2.isFree)
			{
				flag = true;
			}
			break;
		}
		case EntityForMT.tank:
		{
			CarBehavior carBehavior3 = componentInParent as CarBehavior;
			if (carBehavior3 != null && carBehavior3.carWithWeapon && !carBehavior3.isFree)
			{
				flag = true;
			}
			break;
		}
		case EntityForMT.helic:
		{
			HelicopterBehavior helicopterBehavior = componentInParent as HelicopterBehavior;
			if (helicopterBehavior != null && !helicopterBehavior.isFree)
			{
				flag = true;
			}
			break;
		}
		case EntityForMT.allCarBoat:
		{
			CarBehavior carBehavior = componentInParent as CarBehavior;
			if (carBehavior != null && !carBehavior.isFree)
			{
				flag = true;
			}
			break;
		}
		}
		if (flag)
		{
			curMTCheckpoint.OnChangeCheckPoint(this);
		}
	}

	public void SetArrowTarget(Vector3 priv, Vector3 target)
	{
		bool flag = false;
		if (arrow == null || bigArrow == null)
		{
			if (arrow != null)
			{
				arrow.SetActive(false);
			}
			if (bigArrow != null)
			{
				bigArrow.SetActive(false);
			}
			return;
		}
		arrow.SetActive(false);
		bigArrow.SetActive(false);
		if (target == Vector3.zero)
		{
			arrow.SetActive(false);
			bigArrow.SetActive(false);
			return;
		}
		if (priv == Vector3.zero)
		{
			flag = false;
		}
		else
		{
			Vector3 from = priv - base.transform.position;
			Vector3 to = target - base.transform.position;
			float num = Vector3.Angle(from, to);
			if (num < 110f)
			{
				flag = true;
			}
		}
		arrow.SetActive(!flag);
		bigArrow.SetActive(flag);
		arrow.transform.LookAt(target);
		bigArrow.transform.LookAt(target);
	}

	public void SetStateCheckpoint(stateCP needState, bool force = false)
	{
		curState = needState;
		switch (curState)
		{
		case stateCP.hide:
			if (colliderMT != null)
			{
				colliderMT.enabled = false;
			}
			base.gameObject.SetActive(false);
			if (noActiveObj != null && noActiveObj.activeSelf)
			{
				noActiveObj.SetActive(false);
			}
			if (activeObj != null && activeObj.activeSelf)
			{
				activeObj.SetActive(false);
			}
			break;
		case stateCP.show:
			base.gameObject.SetActive(true);
			if (colliderMT != null)
			{
				colliderMT.enabled = false;
			}
			if (noActiveObj != null && !noActiveObj.activeSelf)
			{
				noActiveObj.SetActive(true);
			}
			if (activeObj != null && activeObj.activeSelf)
			{
				activeObj.SetActive(false);
			}
			break;
		case stateCP.showAndActiv:
			base.gameObject.SetActive(true);
			if ((bool)curMTCheckpoint && curMTCheckpoint.pointer != null)
			{
				curMTCheckpoint.pointer.SetNewTargetVector(base.transform.position);
			}
			else
			{
				BCWDebug.Log("WTF");
			}
			if (colliderMT != null)
			{
				colliderMT.enabled = true;
			}
			if (noActiveObj != null && noActiveObj.activeSelf)
			{
				noActiveObj.SetActive(false);
			}
			if (activeObj != null && !activeObj.activeSelf)
			{
				activeObj.SetActive(true);
			}
			break;
		}
	}
}
